From 3321c3c8e9489348f03aba13bc45eb155c90995e Mon Sep 17 00:00:00 2001 From: "kaf24@localhost.localdomain" Date: Sat, 12 Aug 2006 16:18:08 +0100 Subject: [PATCH] [XEN] Add a warning about changeable size of shared_info structure. sizeof(shared_info_t) can change even in compatible hypervisor versions. Add a clear warning about this, and fix the few places relying on it. In addition, add some padding to arch_shared_info, to allow future additions to the structure without breaking known offsets of members following it in the shared info. Signed-off-by: John Levon --- tools/libxc/xc_hvm_build.c | 2 +- tools/libxc/xc_linux_build.c | 4 ++-- tools/libxc/xc_linux_restore.c | 2 +- xen/include/public/arch-ia64.h | 2 ++ xen/include/public/arch-powerpc.h | 1 + xen/include/public/arch-x86_32.h | 1 + xen/include/public/arch-x86_64.h | 1 + xen/include/public/xen.h | 6 +++++- 8 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/libxc/xc_hvm_build.c b/tools/libxc/xc_hvm_build.c index d374631913..3aebbbe8ef 100644 --- a/tools/libxc/xc_hvm_build.c +++ b/tools/libxc/xc_hvm_build.c @@ -303,7 +303,7 @@ static int setup_guest(int xc_handle, xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, shared_info_frame)) == 0 ) goto error_out; - memset(shared_info, 0, sizeof(shared_info_t)); + memset(shared_info, 0, PAGE_SIZE); /* Mask all upcalls... */ for ( i = 0; i < MAX_VIRT_CPUS; i++ ) shared_info->vcpu_info[i].evtchn_upcall_mask = 1; diff --git a/tools/libxc/xc_linux_build.c b/tools/libxc/xc_linux_build.c index 9e7d39e34a..f3649d4314 100644 --- a/tools/libxc/xc_linux_build.c +++ b/tools/libxc/xc_linux_build.c @@ -593,7 +593,7 @@ static int setup_guest(int xc_handle, xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, shared_info_frame); printf("shared_info = %p, err=%s frame=%lx\n", shared_info, strerror (errno), shared_info_frame); - //memset(shared_info, 0, sizeof(shared_info_t)); + //memset(shared_info, 0, PAGE_SIZE); /* Mask all upcalls... */ for ( i = 0; i < MAX_VIRT_CPUS; i++ ) shared_info->vcpu_info[i].evtchn_upcall_mask = 1; @@ -1064,7 +1064,7 @@ static int setup_guest(int xc_handle, /* shared_info page starts its life empty. */ shared_info = xc_map_foreign_range( xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, shared_info_frame); - memset(shared_info, 0, sizeof(shared_info_t)); + memset(shared_info, 0, PAGE_SIZE); /* Mask all upcalls... */ for ( i = 0; i < MAX_VIRT_CPUS; i++ ) shared_info->vcpu_info[i].evtchn_upcall_mask = 1; diff --git a/tools/libxc/xc_linux_restore.c b/tools/libxc/xc_linux_restore.c index ad1d916d55..4f944d6a32 100644 --- a/tools/libxc/xc_linux_restore.c +++ b/tools/libxc/xc_linux_restore.c @@ -737,7 +737,7 @@ int xc_linux_restore(int xc_handle, int io_fd, /* Copy saved contents of shared-info page. No checking needed. */ page = xc_map_foreign_range( xc_handle, dom, PAGE_SIZE, PROT_WRITE, shared_info_frame); - memcpy(page, shared_info, sizeof(shared_info_t)); + memcpy(page, shared_info, PAGE_SIZE); munmap(page, PAGE_SIZE); /* Uncanonicalise the pfn-to-mfn table frame-number list. */ diff --git a/xen/include/public/arch-ia64.h b/xen/include/public/arch-ia64.h index ce71c736c8..23cdf015e8 100644 --- a/xen/include/public/arch-ia64.h +++ b/xen/include/public/arch-ia64.h @@ -297,6 +297,8 @@ struct arch_shared_info { /* Interrupt vector for event channel. */ int evtchn_vector; + + uint64_t pad[32]; }; typedef struct arch_shared_info arch_shared_info_t; diff --git a/xen/include/public/arch-powerpc.h b/xen/include/public/arch-powerpc.h index 17b6bbd257..139b945e75 100644 --- a/xen/include/public/arch-powerpc.h +++ b/xen/include/public/arch-powerpc.h @@ -107,6 +107,7 @@ typedef struct vcpu_guest_context vcpu_guest_context_t; DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t); struct arch_shared_info { + uint64_t pad[32]; }; struct arch_vcpu_info { diff --git a/xen/include/public/arch-x86_32.h b/xen/include/public/arch-x86_32.h index 096ab9736d..9eece83813 100644 --- a/xen/include/public/arch-x86_32.h +++ b/xen/include/public/arch-x86_32.h @@ -191,6 +191,7 @@ struct arch_shared_info { /* Frame containing list of mfns containing list of mfns containing p2m. */ xen_pfn_t pfn_to_mfn_frame_list_list; unsigned long nmi_reason; + uint64_t pad[32]; }; typedef struct arch_shared_info arch_shared_info_t; diff --git a/xen/include/public/arch-x86_64.h b/xen/include/public/arch-x86_64.h index 715a538f04..a92387f125 100644 --- a/xen/include/public/arch-x86_64.h +++ b/xen/include/public/arch-x86_64.h @@ -261,6 +261,7 @@ struct arch_shared_info { /* Frame containing list of mfns containing list of mfns containing p2m. */ xen_pfn_t pfn_to_mfn_frame_list_list; unsigned long nmi_reason; + uint64_t pad[32]; }; typedef struct arch_shared_info arch_shared_info_t; diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index 57d5895b9e..6cc0ee9c81 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -376,7 +376,11 @@ typedef struct vcpu_info vcpu_info_t; /* * Xen/kernel shared data -- pointer provided in start_info. - * NB. We expect that this struct is smaller than a page. + * + * This structure is defined to be both smaller than a page, and the + * only data on the shared page, but may vary in actual size even within + * compatible Xen versions; guests should not rely on the size + * of this structure remaining constant. */ struct shared_info { struct vcpu_info vcpu_info[MAX_VIRT_CPUS]; -- 2.30.2